﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataContracts;

namespace ServiceImplementation.Translator
{
    /// <summary>
    /// Define RoleViewDTO Translator
    /// </summary>
    class RoleViewDTOTranslator
    {
        /// <summary>
        /// To Translate RoleBusinessEntity to RoleViewDTO
        /// </summary>
        /// <param name="roleBE"></param>
        /// <returns></returns>
        public static DataContracts.RoleViewDTO TranslateBusinessToDTO(BLL.Role roleBE)
        {

            DataContracts.RoleViewDTO roleViewDTO = new DataContracts.RoleViewDTO();
            roleViewDTO.RoleId = roleBE.RoleId;
            roleViewDTO.RoleName = roleBE.RoleName;
            roleViewDTO.AuthorityName = roleBE.Authorities[0].AuthorityName;
            roleViewDTO.LevelName = roleBE.Authorities[0].Level.LevelName;            

            return roleViewDTO;
        }

        /// <summary>
        /// To Translate RoleViewDTO to RoleBusinessEntity 
        /// </summary>
        /// <param name="roleViewDTO"></param>
        /// <returns></returns>
        public static BLL.Role TranslateDTOToBusiness(RoleViewDTO roleViewDTO)
        {
            BLL.Role role = new BLL.Role();
            role.RoleId =roleViewDTO.RoleId;
            role.RoleName = roleViewDTO.RoleName;
            BLL.Authority authority = new BLL.Authority();
            BLL.AuthorityLevel authorityLevel = new BLL.AuthorityLevel();

            authority.AuthorityName = roleViewDTO.AuthorityName;
            authorityLevel.LevelName = roleViewDTO.LevelName;

            role.Authorities.Add(authority);
            role.Authorities[0].Level = authorityLevel;

            return role;
        }

    }
}
